
add_custom_target(lib)

set(LIB_SHARED_TARGET ${LIB_TARGET_NAME})
set(LIB_STATIC_TARGET ${LIB_TARGET_NAME}_static)

if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()

set(LIB_TARGET_SOURCES)

set(LIB_PUBLIC_HEADERS
    ${PROJECT_SOURCE_DIR}/include/data_scene.h
    ${PROJECT_SOURCE_DIR}/include/data_manager.h
)

#################################### BUILD LIB ##################################
# add_subdirectory(common)
# add_subdirectory(filter)
# add_subdirectory(vis)
# add_subdirectory(fit)
# add_subdirectory(track)

list(APPEND LIB_TARGET_SOURCES
    file_helper.cpp
    data_scene_impl.cpp
    data_scene.cpp
    data_manager.cpp)

######################## SHARED LIBRARY #######################

add_library(${LIB_SHARED_TARGET} SHARED
    ${LIB_TARGET_SOURCES})

set_target_properties(${LIB_SHARED_TARGET} PROPERTIES
    CXX_STANDARD "17"
    CXX_STANDARD_REQUIRED "YES"
    CXX_EXTENSIONS "NO"
    ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
)

set_target_properties(${LIB_SHARED_TARGET} PROPERTIES PUBLIC_HEADER "${LIB_PUBLIC_HEADERS}")
set_target_properties(${LIB_SHARED_TARGET} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs=ALL -Wl,--no-as-needed -lpthread")
set_target_properties(${LIB_SHARED_TARGET} PROPERTIES DEBUG_POSTFIX ${TARGET_DEBUG_POSTFIX})
set_target_properties(${LIB_SHARED_TARGET} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

######################## SHARED LIBRARY #######################

add_library(${LIB_STATIC_TARGET} STATIC
    ${LIB_TARGET_SOURCES})


set_target_properties(${LIB_STATIC_TARGET} PROPERTIES
    CXX_STANDARD "17"
    CXX_STANDARD_REQUIRED "YES"
    CXX_EXTENSIONS "NO"
    ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
)

set_target_properties(${LIB_STATIC_TARGET} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs=ALL")
set_target_properties(${LIB_STATIC_TARGET} PROPERTIES DEBUG_POSTFIX ${TARGET_DEBUG_POSTFIX})
set_target_properties(${LIB_STATIC_TARGET} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

##########################################

add_dependencies(lib ${LIB_SHARED_TARGET} ${LIB_STATIC_TARGET})

##########################################

INSTALL(TARGETS ${LIB_SHARED_TARGET} ${LIB_STATIC_TARGET}
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
        PUBLIC_HEADER DESTINATION "include"
)

###############################################################################

#################################### BUILD EXEC ###############################


add_executable(${TEST_TARGET_NAME}
    main.cpp
    )

set_target_properties(${TEST_TARGET_NAME} PROPERTIES
    CXX_STANDARD "17"
    CXX_STANDARD_REQUIRED "YES"
    CXX_EXTENSIONS "NO"
    ARCHIVE_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
    LIBRARY_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
    RUNTIME_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
    )

set_target_properties(${TEST_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${TARGET_DEBUG_POSTFIX})
set_target_properties(${TEST_TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION})

if(DEFINED AMBA_SDK_DIR)
    target_link_libraries(
        ${TEST_TARGET_NAME}
        ${LIB_TARGET_NAME}
        ${AMBA_SDK_LIBS}
        ${AMBA_SDK_OSS_LIBS}
        ${CMAKE_THREAD_LIBS_INIT}         
    )
else()
    target_link_libraries(
        ${TEST_TARGET_NAME}
        ${LIB_TARGET_NAME}  
        boost_json
        ${CMAKE_THREAD_LIBS_INIT} 
        ${Boost_LIBRARIES}
        ${OpenCV_LIBS}
    )
endif()










